/*
Authors: Eli Yucht 300388949 and Lior Fass 300069705
Project: SCP (Switch Schedule Policy)
Description: Flow class
*/


#ifndef FLOW_H
#define FLOW_H

#include <iostream>
using namespace std;

#include <cstring> // for strlen(), strcmp()
#include <cstdlib> // for atoi(), atol()

#define MAX_IP_ADD_LEN 16
#define BUF_SIZE 50 // sufficient room for 2 long int + space + NULL terminator

/*Packet is a struct that contain the following fields:
	1. long int pktID - the ID of the packet
	2. long int arrive_time - the arriving time of the packet
	3. unsigned short int length - number of bytes in packet
	4. Packet* next_packet - a pointer to the next arrived packet (or NULL)*/

struct Packet
{
	long int pktID, arrive_time;
	unsigned short int length;
	Packet* next_packet;

	Packet()
	{
		pktID = -1;
		arrive_time = -1;
		length = -1;
		next_packet = NULL;
	}
}; 


/* Flow class declaration
	Flow is a class that defined by 4 fields:

	1. char src_ip_add[MAX_IP_ADD_LEN] - the source ip address of the flow
	2. char des_ip_add[MAX_IP_ADD_LEN] - the destination ip address of the flow
	3. unsigned short int src_port - the source port of the flow
	4. unsigned short int des_port - the destination port of the flow

	It also has the following fields:
	5. unsigned short int weight - the weight of the flow (for WRR/DRR)
	6. unsigned short int credit - the current credit of the flow (for DRR)
	7. Packet* head_packet_queue - pointer to the head of the packets queue
	8. Packet* tail_packet_queue - pointer to the tail (end) of the packets queue
	9. Flow* next_flow - a pointer to the next arrived flow (or NULL)


	*/
class Flow
{
public:
	Flow(char* sadd,unsigned short int sport,char* dadd,
		unsigned short int dport,unsigned short int wgt);
	~Flow();

	bool Check_Flow(char* sadd, unsigned short int sport, char* dadd, unsigned short int dport);
	int Add_Pkt_To_Flow(long int pktID, long int arrived_time, unsigned short int length);
	long int Remove_Pkt_From_Flow(long int time, FILE* outfile_p);

	unsigned short int getWeight();
	unsigned short int Get1PacketLength();
	unsigned int GetCredit();

	void AddCredit(int quantum);
	void ReduceCredit();
	void ZerorizeCredit();
	

	Flow* next_flow;

private:
	char src_ip_add[MAX_IP_ADD_LEN];
	char des_ip_add[MAX_IP_ADD_LEN];
	unsigned short int src_port;
	unsigned short int des_port;
	unsigned short int weight;
	unsigned int credit;

	Packet* head_packet_queue;
	Packet* tail_packet_queue;
	

};

#endif // FLOW_H